#include <stdio.h>
#include <stdlib.h>

typedef struct timetable_t
{
	int start;
	int end;
	int flag;	//1:execute; 0:not execute
}TIMETABLE;
TIMETABLE timetable[200];
TIMETABLE *NA, *NB;
void travel(TIMETABLE *t1, int j, int n1, TIMETABLE *t2, int k, int n2);
int comp(const void *a, const void *b)
{
	int t;
	t = ((TIMETABLE *)a)->start - ((TIMETABLE *)b)->start;
	if (t == 0)
		t = ((TIMETABLE *)a)->end - ((TIMETABLE *)b)->end;
	return t;
}
int main(int argc, char **argv)
{
	int n, t, i, na, nb, j, k;
	int t1, t2, t3, t4;
	char buffer[100];
	int a, b;

	fgets(buffer, sizeof buffer, stdin);
	sscanf(buffer, "%d", &n);
	NA = timetable;
	for (i = 0; i < n; i++) {
		fgets(buffer, sizeof buffer, stdin);
		sscanf(buffer, "%d", &t);
		fgets(buffer, sizeof buffer, stdin);
		sscanf(buffer, "%d %d", &na, &nb);
		a = b = 0;
		NB = NA + na;
		for (j = 0; j < na + nb; j++) {
			fgets(buffer, sizeof buffer, stdin);
			sscanf(buffer, "%d:%d %d:%d", &t1, &t2, &t3, &t4);
			timetable[j].start = t1 * 60 + t2;
			timetable[j].end = t3 * 60 + t4 + t;
			timetable[j].flag = 0;
		}
		qsort(NA, na, sizeof(TIMETABLE), comp);
		qsort(NB, nb, sizeof(TIMETABLE), comp);
		j = k = 0;
		int count = 0;
		int num;
		while (1) {
			if (j >= na) {
				num = 0;
				for (count = k; count < nb; count++) {
					if (!NB[count].flag)
						num++;
				}
				b += num;
				break;
			}
			if (k >= nb) {
				num = 0;
				for (count = j; count < na; count++) {
					if (!NA[count].flag)
						num++;
				}
				a += num;
				break;
			}
			if (!NA[j].flag && NA[j].start < NB[k].start) {
				a++;
				NA[j].flag = 1;
				travel(NA, j, na, NB, k, nb);
				j++;
			}
			else if (!NB[k].flag && NA[j].start > NB[k].start) {
				b++;
				NB[k].flag = 1;
				travel(NB, k, nb, NA, j, na);
				k++;
			}
			else if (!NA[j].flag && !NB[k].flag && NA[j].start == NB[k].start) {
				a++;
				b++;
				NA[j].flag = 1;
				NB[k].flag = 1;
				if (NA[j].end < NB[k].end) {
					travel(NA, j, na, NB, k, nb);
					travel(NB, k, nb, NA, j, na);
				}
				else {
					travel(NB, k, nb, NA, j, na);
					travel(NA, j, na, NB, k, nb);
				}
				j++;
				k++;
			}
			else {
				if (NA[j].flag) {
					j++;
				}
				if (NB[k].flag)
					k++;
			}
		}
		printf("Case #%d: %d %d\n", i + 1, a, b);
	}
	return 0;
}

void travel(TIMETABLE *t1, int j, int n1, TIMETABLE *t2, int k, int n2)
{
	int i;
	
	for (i = k; i < n2; i++) {
		if (!t2[i].flag && t1[j].end <= t2[i].start) {
			t2[i].flag = 1;
			travel(t2, i, n2, t1, j, n1);
			break;
		}
	}
}
